package com.interview.a_多线程.a_实现线程.c_其他实现;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池 只是具有了建线程功能的 包装类
 * 可以 也 不可以 说成线程的实现方式
 * <p>
 * 线程池创建线程实现的原理
 * 也是 newThread(rannable)
 */
public class ThreadPool {
    public static void main(String[] args) {
        Thread thread = new Thread();
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 1000; i++) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName());
                }
            });
        }
    }
}
